﻿Imports System.Data.SqlClient
Public Class clsPedidosConcepto
    Private mintIdConcepto As Integer
    Private mstrCodigo As String
    Private mstrNombre As String
    Public Property idConcepto() As Integer
        Get
            Return mintIdConcepto
        End Get
        Set(ByVal value As Integer)
            mintIdConcepto = value
        End Set
    End Property

    Public Property Codigo() As String
        Get
            Return mstrCodigo
        End Get
        Set(ByVal value As String)
            mstrCodigo = value
        End Set
    End Property
    Public Property Nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Sub New()
        mintIdConcepto = 0
        mstrCodigo = ""
        mstrNombre = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into PedidosConcepto (" & _
                            "IdConcepto," & _
                            "Codigo," & _
                            "Nombre)" & _
                            " VALUES (" & _
                            "@IdConcepto," & _
                            "@Codigo," & _
                            "@Nombre)" & _
                            " SELECT SCOPE_IDENTITY()"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdConcepto", mintIdConcepto)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el concepto ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
